package com.icss.ah.promotion.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.icss.ah.base.bean.SyncSelectTree;

@Service
@Transactional
public class PromotionService {
	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;
	

	
	public List getProductList(String modelKey,HashMap map) {
		List list = new ArrayList();
		try {
			list = sqlSessionTemplate.selectList(modelKey,map);
			list = list == null ? new ArrayList() : list;
		} catch (Exception ex) {
			ex.printStackTrace();
			list = new ArrayList();
		} 
		return list;
	}
	
	public List getPromotionList(String modelKey,HashMap map) {
		List list = new ArrayList();
		try {
			list = sqlSessionTemplate.selectList(modelKey,map);
			list = list == null ? new ArrayList() : list;
		} catch (Exception ex) {
			ex.printStackTrace();
			list = new ArrayList();
		} 
		return list;
	}
	
	public Long getPromotionListCount(String modelKey,HashMap map) {
		Long reValue = 0l;
		try {
			reValue = (Long)sqlSessionTemplate.selectOne(modelKey,map);
		} catch (Exception ex) {
			ex.printStackTrace();
		} 
		return reValue;
	}
	
	
	
	
	public void add(String modelKey,HashMap map) {
		sqlSessionTemplate.insert(modelKey,map);
	}
	
	public void addProduct(String modelKey,HashMap map) {
		sqlSessionTemplate.insert(modelKey,map);
	}
	
	
	public void edit(String modelKey,HashMap map) {
		sqlSessionTemplate.update(modelKey,map);
	}
	
	public Map getPromotionDetail(String modelKey,HashMap map) {
		Map re = new HashMap();
		try {
			re = sqlSessionTemplate.selectOne(modelKey,map);
		} catch (Exception ex) {
			ex.printStackTrace();
			re = new HashMap();
		} 
		return re;
	}
	
	public void delProduct(String modelKey,HashMap map) {
		sqlSessionTemplate.delete(modelKey,map);
	}
	
	public void del(String modelKey,HashMap map) {
		try {
			sqlSessionTemplate.delete(modelKey,map);
			
		} catch (Exception ex) {
			ex.printStackTrace();
			
		} 
	}
	public boolean updateStatus(HashMap map){
		boolean result = false;
		try{
			sqlSessionTemplate.update("PromotionBean.updateStatus", map);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
	
}
